package cheme.Application;

import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import cheme.Application.actions.ChemeActionFactory;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor
{
	//	 Actions - important to allocate these only in makeActions, and then use them
	// in the fill methods.  This ensures that the actions aren't recreated
	// when fillActionBars is called with FILL_PROXY.
	private IWorkbenchAction exitAction;
	private IWorkbenchAction aboutAction;
	
	// private OpenViewAction openViewAction;

//	private IWorkbenchAction copyAction;
//	private IWorkbenchAction cutAction;
//	private IWorkbenchAction pasteAction;
	
	private IWorkbenchAction undoAction;
	private IWorkbenchAction redoAction;
//	private IWorkbenchAction zoomInAction;
//	private IWorkbenchAction zoomOutAction;
//	private IWorkbenchAction zoomSelectorAction;

//	private IWorkbenchAction selectAllAction;
	private IWorkbenchAction deleteAction;

	private IWorkbenchAction newFileAction;
	private IWorkbenchAction openFileAction;
	private IWorkbenchAction saveFileAction;
	private IWorkbenchAction saveFileAsAction;
	
	private IWorkbenchAction consoleAction;	

	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer)
	{
		super(configurer);
	}

	protected void makeActions(IWorkbenchWindow window)
	{
		// Creates the actions and registers them.
		// Registering is needed to ensure that key bindings work.
		// The corresponding commands keybindings are defined in the plugin.xml file.
		// Registering also provides automatic disposal of the actions when
		// the window is closed.
		
		newFileAction = ChemeActionFactory.NEW.create(window);
		openFileAction = ChemeActionFactory.OPEN.create(window);
		saveFileAction = ChemeActionFactory.SAVE.create(window);
		saveFileAsAction = ChemeActionFactory.SAVEAS.create(window);
		
		exitAction = ActionFactory.QUIT.create(window);
		register(exitAction);
		
//		copyAction = ActionFactory.CUT.create(window);
//		register(copyAction);
//		cutAction = ActionFactory.COPY.create(window);
//		register(cutAction);
//		pasteAction = ActionFactory.PASTE.create(window);
//		register(pasteAction);
		
//		selectAllAction = ActionFactory.SELECT_ALL.create(window);
//		register(selectAllAction);
		
		deleteAction = ActionFactory.DELETE.create(window);
		register(deleteAction);

		aboutAction = ActionFactory.ABOUT.create(window);
		register(aboutAction);
		
		undoAction = ActionFactory.UNDO.create(window);
		redoAction = ActionFactory.REDO.create(window);
		
		/*
		addRetargetAction(new UndoRetargetAction());
		addRetargetAction(new RedoRetargetAction());
		
		addRetargetAction(new DeleteRetargetAction());
		
		addRetargetAction(new ZoomInRetargetAction());
		addRetargetAction(new ZoomOutRetargetAction());
				
		addRetargetAction(new CopyRetargetAction());
		addRetargetAction(new PasteRetargetAction());
		*/
		
		consoleAction = ChemeActionFactory.CONSOLE.create(window);

//		 openViewAction = new OpenViewAction(window, "Open Another Message View", View.ID);
//		 register(openViewAction);
	}
	
	protected void fillMenuBar(IMenuManager menuBar)
	{
		MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);

		// File
		fileMenu.add(newFileAction);
		fileMenu.add(openFileAction);
		fileMenu.add(saveFileAction);
		fileMenu.add(saveFileAsAction);
		fileMenu.add(new Separator());
		fileMenu.add(exitAction);
		menuBar.add(fileMenu);
		
		MenuManager editMenu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
		editMenu.add(undoAction);
		editMenu.add(redoAction);
		editMenu.add(new Separator());
		editMenu.add(deleteAction);
//		editMenu.add(new Separator());
//		editMenu.add(selectAllAction);
		
//		editMenu.add(new Separator());
//		editMenu.add(copyAction);
//		editMenu.add(cutAction);
//		editMenu.add(pasteAction);
		menuBar.add(editMenu);
		
		// Help
		MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
		helpMenu.add(consoleAction);
		helpMenu.add(new Separator());
		helpMenu.add(aboutAction);
		menuBar.add(helpMenu);
	}

	@Override
	protected void fillCoolBar(ICoolBarManager coolBar)
	{
		IToolBarManager fileToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
		coolBar.add(new ToolBarContributionItem(fileToolbar, "main"));

		fileToolbar.add(newFileAction);
		fileToolbar.add(openFileAction);
		fileToolbar.add(saveFileAction);
		fileToolbar.add(saveFileAsAction);
		fileToolbar.add(new Separator());
		
		IToolBarManager editToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
		coolBar.add(new ToolBarContributionItem(editToolbar, "edit"));
	
		editToolbar.add(undoAction);
		editToolbar.add(redoAction);
		editToolbar.add(new Separator());
		editToolbar.add(deleteAction);
		
//		editToolbar.add(new Separator());
//		editToolbar.add(copyAction);
//		editToolbar.add(cutAction);
//		editToolbar.add(pasteAction);
		
		// Add a group marker indicating where action set menus will appear.
//		coolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
	}
	
	
}
